home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / newsgroups / misc.19980901-19981211 / 000237_news@newsmaster….columbia.edu _Wed Oct 28 17:00:08 1998.msg < prev    next >
Internet Message Format  |  2020-01-01  |  4KB

  1. Return-Path: <news@newsmaster.cc.columbia.edu>
  2. Received: from newsmaster.cc.columbia.edu (newsmaster.cc.columbia.edu [128.59.35.30])
  3.     by watsun.cc.columbia.edu (8.8.5/8.8.5) with ESMTP id RAA10180
  4.     for <kermit.misc@watsun.cc.columbia.edu>; Wed, 28 Oct 1998 17:00:08 -0500 (EST)
  5. Received: (from news@localhost)
  6.     by newsmaster.cc.columbia.edu (8.8.5/8.8.5) id RAA13286
  7.     for kermit.misc@watsun; Wed, 28 Oct 1998 17:00:07 -0500 (EST)
  8. Path: news.columbia.edu!watsun.cc.columbia.edu!fdc
  9. From: fdc@watsun.cc.columbia.edu (Frank da Cruz)
  10. Newsgroups: comp.protocols.kermit.misc
  11. Subject: Re: sending variables on the command line
  12. Date: 28 Oct 1998 22:00:06 GMT
  13. Organization: Columbia University
  14. Lines: 88
  15. Message-ID: <718456$a8l$1@apakabar.cc.columbia.edu>
  16. References: <71810c$31v$1@supernews.com>
  17. NNTP-Posting-Host: watsun.cc.columbia.edu
  18. Xref: news.columbia.edu comp.protocols.kermit.misc:9437
  19.  
  20. In article <71810c$31v$1@supernews.com>, Michael Rose <mike@tegris.com> wrote:
  21. : I have a script that I would like to send variables from the command prompt.
  22. : kermit  script-name  variable1  variable2  variable3 variable4
  23. Let's assume you are talking about C-Kermit 6.0.
  24.  
  25. : $kermit maillogs 10.2.2.14 joebloe joepasswd maillog
  26. This can't work because "10.2.2.14", "joebloe", "joepasswd", and "maillog"
  27. are not valid C-Kermit command-line arguments.
  28.  
  29. : Any help would be greatly appreciated.
  30. The trick that you are looking for is documented, somewhat obscurely,
  31. on pages 353, 383, 469, and 513 of "Using C-Kermit", 2nd edition:
  32.  
  33.  1. If you put an "=" sign (surrounded by whitespace) on the command line,
  34.     the following words are ignored, but still assigned to the argument
  35.     vector array, \&@[].
  36.  
  37.  2. You can use a FOR loop to loop through the argument vector array
  38.     elements until you find the one whose value is "=".
  39.  
  40.  3. The ones after that are your variables.
  41.  
  42. Example:
  43.  
  44.   $kermit maillogs = 10.2.2.14 joebloe joepasswd maillog
  45.  
  46. (note insertion of "=" sign)
  47.  
  48. The maillogs script can retrieve the arguments as follows:
  49.  
  50.   local \%i \%k
  51.   for \%i 0 \v(args)-1 1 {
  52.       xif equal "\&@[\%k]" "=" {
  53.           assign \%k \%i
  54.           increment \%k
  55.           break
  56.       }
  57.   }
  58.  
  59. At this point, if \%k is defined, it is the index of your first variable:
  60.  
  61.   \&@[\%k]   is 10.2.2.14
  62.   \&@[\%k+1] is joebloe
  63.   \&@[\%k+2] is joepasswd
  64.   \&@[\%k+3] is joepasswd
  65.   \&@[\%k+4] is maillog
  66.  
  67. Granted, this is obscure, nonintuitive, and cryptic.  The next version
  68. of C-Kermit will include a much better way to access these variables:
  69. within the script, you will be able to refer to these variables like this:
  70.  
  71.   \%0 = the name of the script file   (maillogs)
  72.   \%1 = the first argument after "="  (10.2.2.14)
  73.   \%2 = the second argument after "=" (joeblow)
  74.  
  75. and so on.  (This feature is not in C-Kermit 6.1 Beta.05; it will be in
  76. 7.0 Alpha.01 and in the next release of K-95 -- watch this space for
  77. announcements.)  
  78.  
  79. By the way, the reason for the "=" is to allow a mixture of arguments to
  80. Kermit and arguments to the script on the same command line.  Thus, both
  81. examples above would work just as well if your command line was:
  82.  
  83.   $kermit maillogs -i -Q -Y -H = 10.2.2.14 joebloe joepasswd maillog
  84.  
  85. And finally, note that you can remove the word "kermit" from the command line
  86. if you first:
  87.  
  88.   chmod +x maillogs
  89.  
  90. and put:
  91.  
  92.   #!/usr/local/bin/kermit
  93.  
  94. as the first line (substitute the actual pathname of the Kermit executable).
  95.  
  96. Now you can just run the script as if it were a shell script (except that
  97. you still need the "=" to precede the argument list):
  98.  
  99.   $maillogs = 10.2.2.14 joebloe joepasswd maillog
  100.  
  101. See p.513 for details.
  102.  
  103. - Frank